package com.dj.mingkong.admin.biz.controller.music;

import com.dj.mingkong.admin.biz.controller.music.vo.request.AlbumMusicUpdateVo;
import com.dj.mingkong.admin.biz.controller.music.vo.response.AlbumMusicVo;
import com.dj.mingkong.admin.biz.service.music.AlbumMusicService;
import com.dj.mingkong.common.annotation.HasRoles;
import com.dj.mingkong.common.enums.RoleEnum;
import com.dj.mingkong.common.infrastructure.base.dto.rest.RestResponse;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 专辑音乐管理
 *
 * @author zenglonghui
 * @date: 2022/8/16 15:26
 */
@RestController
@RequestMapping("/album/music")
@HasRoles(RoleEnum.ADMIN)
public class AlbumMusicController {
    @Resource
    private AlbumMusicService albumMusicService;

    /**
     * 获取音乐所属专辑信息
     *
     * @param musicId 音乐Id
     * @return AlbumMusicVo
     */
    @GetMapping("/listByMusicId/{musicId}")
    public RestResponse<AlbumMusicVo> listByMusicId(@PathVariable("musicId") Long musicId) {
        return RestResponse.success(albumMusicService.listByMusicId(musicId));
    }

    /**
     * 修改数据
     *
     * @param updateVo 实例对象
     * @return 是否成功，true-成功，false-失败
     * @throws RuntimeException albumMusicVo为空的时候会抛出运行时异常
     */
    @PostMapping("/updateByMusicId")
    public RestResponse<Boolean> updateByMusicId(@RequestBody @Validated AlbumMusicUpdateVo updateVo) {
        albumMusicService.updateByMusicId(updateVo);
        return RestResponse.buildSuccess();
    }
}
